var app = getApp();
var Bmob = require('../../utils/bmob.js');
Page({
  data: {
    mobilePhoneNumber: '点击绑定',//设定手机号码初始值
    userInfo: app.globalData.userInfo
  },
  onLoad: function () {

  },
  onShow: function () {
    var self = this;
    //显示头像和昵称
    if (Bmob.User.current() != null) {
      var mobilePhoneNumber = Bmob.User.current().mobilePhoneNumber;
      if (app.isNullEmptyOrUndefined(mobilePhoneNumber)){
        mobilePhoneNumber = app.globalData.mobilePhoneNumber;
      }

      var userInfo = {};
      userInfo.avatarUrl = Bmob.User.current().userPic;
      userInfo.nickName = Bmob.User.current().nickName;

      this.setData({
        mobilePhoneNumber: app.isNotNullEmptyOrUndefined(mobilePhoneNumber) ? mobilePhoneNumber : this.data.mobilePhoneNumber ,
        userInfo: userInfo
      });
    }
  },
  accountReg: function (e) {
    var self = this;
    if (e.detail.rawData != null) {
      app.userBmobLogin(e.detail.userInfo);
      //更新数据
      self.setData({
        userInfo: app.globalData.userInfo
      });
      //如果手机号码是空的
      if (app.isNullEmptyOrUndefined(app.globalData.mobilePhoneNumber)) {
        wx.navigateTo({
          url: '../register/register',
        });
      }
      // else {
      //   var self = this;
      //   wx.showModal({
      //     title: '退出登录',
      //     content: '确认退出登录？',
      //     success: function (res) {
      //       if (res.confirm) {
      //         Bmob.User.logOut();
      //         self.setData({
      //           mobilePhoneNumber: '点击绑定'
      //         });
      //       }
      //     }
      //   });
      // }
    }

  },
  businessApply: function (e) { //点击商家入驻
    app.businessApply(e);
  }
});

